package com.andy.beef.login.api

import com.andy.beef.login.bean.TokenBean
import com.andy.beef.login.bean.UserInfoBean
import com.andy.module.BASE_PASSPORT
import com.andy.module.BASE_USER
import com.andy.module.network.RetrofitClient
import com.andy.module.network.SimpleApiService
import com.andy.network.entity.ApiResponse
import retrofit2.http.FieldMap
import retrofit2.http.FormUrlEncoded
import retrofit2.http.POST
import retrofit2.http.Url

/**
 * @creator:LuoFan
 * @date:2022/5/27
 * @description:
 */

//双重校验锁式-单例 封装NetApiService 方便直接快速调用简单的接口
val loginService: LoginApiService by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
    RetrofitClient.getService(LoginApiService::class.java, SimpleApiService.SERVER_URL)
}

interface LoginApiService {

    companion object {
        const val URL_LOGIN_BY_PHONE = BASE_PASSPORT + "mobile/sso/sms-login"
        const val URL_GET_USER_INFO = BASE_USER + "mobile/staff/current-info"
    }

    /**
     * 手机短信登录
     */
    @FormUrlEncoded
    @POST
    suspend fun loginByPhone(
        @FieldMap params: HashMap<String, Any>,
        @Url url: String = URL_LOGIN_BY_PHONE
    ): ApiResponse<TokenBean>


    /**
     * 手机短信登录
     */
    @FormUrlEncoded
    @POST
    suspend fun getUserInfo(@FieldMap params: HashMap<String, Any>, @Url url: String = URL_GET_USER_INFO): ApiResponse<UserInfoBean>
}